<template>
  <div>
    <el-tabs class="box">
      <el-tab-pane label="未读消息" name="first">
        <div
          class="wrap"
          v-for="(item, index) in list"
          :key="index"
          v-show="item.status == 0"
        >
          <span>{{ item.title }}</span>
          <el-button class="btn" @click="change1(item)">标记已读</el-button>
        </div>

        <el-button class="btn1" @click="allDone">全部标记为已读</el-button>
      </el-tab-pane>
      <el-tab-pane label="已读消息" name="second">
        <div
          class="wrap"
          v-for="(item, index) in list"
          :key="index"
          v-show="item.status == 1"
        >
          <span>{{ item.title }}</span>
          <div>
            <el-button @click="change2(item)">删除</el-button>
            <el-button @click="change3(item)">还原未读</el-button>
          </div>
        </div>
        <el-button class="btn1" @click="allchange">全部放入回收站</el-button>
      </el-tab-pane>
      <el-tab-pane label="回收站" name="third">
        <div
          class="wrap"
          v-for="(item, index) in list"
          :key="index"
          v-show="item.status == 2"
        >
          <span>{{ item.title }}</span>
          <el-button class="btn" @click="change1(item)">还原</el-button>
        </div>
        <el-button class="btn1" @click="allremove">全部删除</el-button>
      </el-tab-pane>
    </el-tabs>
  </div>
</template>
<script>
export default {
  data() {
    return {
      list: JSON.parse(localStorage.getItem("list")) || [
        {
          title: "任务1",
          status: 0,
        },
        {
          title: "任务2",
          status: 1,
        },
        {
          title: "任务3",
          status: 2,
        },
        {
          title: "任务4",
          status: 0,
        },
        {
          title: "任务5",
          status: 1,
        },
        {
          title: "任务6",
          status: 2,
        },
      ],
    };
  },
  mounted() {
    this.save();
  },
  methods: {
    save() {
      localStorage.setItem("list", JSON.stringify(this.list));
    },
    allDone() {
      this.list.forEach((item) => {
        if (item.status == 0) {
          item.status = 1;
        }
      });
      this.save();
    },
    allchange() {
      this.list.forEach((item) => {
        if (item.status == 1) {
          item.status = 2;
        }
      });
      this.save();
    },
    allremove() {
      this.list.forEach((item) => {
        if (item.status == 2) {
          item.status = -1;
        }
      });
      this.save();
    },
    change1(item) {
      item.status = 1;
      this.save();
    },
    change2(item) {
      item.status = 2;
      this.save();
    },
    change3(item) {
      item.status = 0;
      this.save();
    },
  },
};
</script>
<style scoped>
.box{
  margin-top: 10px;
  margin-left: 50px;
}
.wrap {
  display: flex;
  justify-content: space-between;
  border-bottom: 1px solid #ccc;
  height: 60px;
  line-height: 50px;
}
.btn{
  height: 40px;
}
.btn1{
  margin-left: -1000px;
}
</style>
